﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;
using System.IO;


public partial class Month_MonthPlanList : System.Web.UI.Page
{
    UserInfoManager dllUserInfoManager = new UserInfoManager();
    MonthDateManager dllMonthDateManager = new MonthDateManager();
    MonthPlanManager dllMonthPlanManager = new MonthPlanManager();
    IBussinessLogic dllMonthPlan = new MonthPlanManager();
    Authentication dllAuthentication = new Authentication();
    DepartmentInfoManager dllDepartment = new DepartmentInfoManager();
    Month_RemindofManager dllMonth_RemindofManager = new Month_RemindofManager();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    DataTable _powerTable = new DataTable();
    QuarterDateManager dllQuarterDateManager = new QuarterDateManager();
    IBussinessLogic dllUserInfo = new UserInfoManager();
    public string TheMonthRemind = "";
    public string PreMonthRemind = "";
    int _isManager = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();

        this.btnDisplay.Enabled = false;
        if (objUserInfo.UserName == "admin")
        {
            this.btnDisplay.Enabled = true;
        }
        Page.RegisterStartupScript("getheighandwidth", "<script>document.getElementById('h1h').value=window.screen.availHeight;document.getElementById('h2w').value= window.screen.width ;</script>");


        //得到月计划信息  
        if (!IsPostBack)
        {

            #region 弹出提醒
            PopupManager dllPopupManager = new PopupManager();
            string _info = dllPopupManager.getPopupInfo();
            if (_info.Length > 0)
            {
                ShowMessage(_info);
            }
            #endregion
            //绑定本月计划
            bindDropDownList(this.drpYear);
            bindDropDownList(this.drpDepartment);
            bindDropDownList(this.drpQuarterDate);
            bindDropDownList(this.drpMonthDate);
            bindGridView(this.gdvMonthList);
            bindGridView(this.gdvPreMonthList);
            bindGridView(this.gdvPreNoCompeleteMonthPlan);
            bindGridView(this.gdvContinueMonthList);

            BindMonthRemind();
        }
        processGridViewForMonth(gdvMonthList);
        processGridViewPre(gdvPreMonthList);
        processGridView(gdvPreNoCompeleteMonthPlan);
        processGridViewForMonth(gdvContinueMonthList);
        //判断是否为经理，非经理锁定部门选择框
        this.drpDepartment.Enabled = false;
        this.btnResolve.Enabled = false;
        this.btnResolve.Visible = false;
        this.btnResolveToUserMonthPlan.Enabled = false;
        IsManager();
        if (objUserInfo.UserName == "admin")
        {
            this.btnResolve.Enabled = true;
            this.btnResolve.Visible = true;
        }
    }

    void IsManager()
    {
        _isManager = dllAuthentication.IsManager(objUserInfo.UserName);
        if (_isManager > 0)
        {
            this.drpDepartment.Enabled = true;
            this.btnResolveToUserMonthPlan.Enabled = true;
            this.btnModifyContinue.Visible = true;
            this.btnModifyMonth.Visible = true;
            this.btnModifyPrevMonth.Visible = true;
            this.btnMonthResolve.Visible = true;
            //this.btnResolve.Visible = true;
            this.btnToExcel.Visible = true;
            this.btnAddMonthSummary.Enabled = true;
            this.btnAddPreMonthSummary.Enabled = true;
            this.btnSaveMonthSummary.Enabled = true;
            this.btnSavePreMonthSummary.Enabled = true;
            this.btnDownMonthSummary.Enabled = true;
            //this.btnDownPreMonth.Enabled = true;
            this.btnUploadMonthSummary.Enabled = true;
            //this.btnUploadPreMonthSummary.Enabled = true;
        }
        else
        {
            this.drpDepartment.Enabled = false;
            this.btnResolveToUserMonthPlan.Visible = false;
            this.btnModifyContinue.Visible = false;
            this.btnModifyMonth.Visible = false;
            this.btnModifyPrevMonth.Visible = false;
            this.btnMonthResolve.Visible = false;
            //this.btnResolve.Visible = false;
            this.btnToExcel.Visible = false;
            this.btnAddMonthSummary.Enabled = false;
            this.btnAddPreMonthSummary.Enabled = false;
            this.btnSaveMonthSummary.Enabled = false;
            this.btnSavePreMonthSummary.Enabled = false;
            this.btnDownMonthSummary.Enabled = false;
            //this.btnDownPreMonth.Enabled = false;
            this.btnUploadMonthSummary.Enabled = false;
            // this.btnUploadPreMonthSummary.Enabled = false;
        }
    }


    /// <summary>
    /// 弹出小窗体事件
    /// </summary>
    /// <param name="msg"></param>
    public void ShowMessage(string msg)
    {
        EeekSoft.Web.PopupWin pop = new EeekSoft.Web.PopupWin();
        this.Controls.Add(pop);
        pop.Text = msg;
        pop.Message = msg;
        pop.Title = System.Configuration.ConfigurationManager.AppSettings["CompanyName"].ToString();
        pop.WindowScroll = true;
        pop.HideAfter = 99999999;
        pop.DockMode = EeekSoft.Web.PopupDocking.BottomLeft;
        pop.OffsetX = int.Parse(Session["_width"].ToString()) - 338;
        pop.ActionType = EeekSoft.Web.PopupAction.MessageWindow;
        pop.OffsetY = 1;
        pop.Width = 220;
        pop.Height = 170;
    }



    /// <summary>
    /// 绑定所有的dropdownlist
    /// </summary>
    /// <param name="_drp"></param>
    void bindDropDownList(DropDownList _drp)
    {
        //部门绑定
        if (_drp.Equals(this.drpDepartment))
        {
            this.drpDepartment.DataSource = dllDepartment.getNoTree();
            this.drpDepartment.DataTextField = "DepartmentName";
            this.drpDepartment.DataValueField = "DepartmentId";
            this.drpDepartment.DataBind();
            ListItem _li = new ListItem("请选择部门");
            this.drpDepartment.Items.Insert(0, _li);
            object[] _value = new object[1];
            _value[0] = objUserInfo.UserName;
            DataTable _userTable = dllUserInfoManager.get(UserInfoManager.field.UserName.ToString(), _value);
            if (_userTable.Rows.Count > 0)
            {
                this.drpDepartment.SelectedIndex = this.drpDepartment.Items.IndexOf(this.drpDepartment.Items.FindByText(_userTable.Rows[0]["DepartmentId"].ToString()));

                if (this.drpDepartment.SelectedItem.Text != _userTable.Rows[0]["DepartmentId"].ToString() && objUserInfo.UserName != "admin" && this.drpDepartment.SelectedItem.Text != _userTable.Rows[0]["PartTimeDepartmentId"].ToString())
                {
                    //this.btnResolve.Enabled = false;
                }
                else
                {
                    // this.btnResolve.Enabled = true;
                }
            }
            if (Request.QueryString["depart"] != null)
            {
                this.drpDepartment.SelectedIndex = this.drpDepartment.Items.IndexOf(this.drpDepartment.Items.FindByValue(Request.QueryString["depart"].ToString()));
            }
        }
        //年份绑定
        if (_drp.Equals(this.drpYear))
        {
            for (int i = 2009; i < 2100; i++)
            {
                ListItem _li = new ListItem(i.ToString(), i.ToString());
                _drp.Items.Add(_li);
            }
            //根据系统日期自动绑定到当前年份
            //string _year = DateTime.Now.Year.ToString();
            //this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_year));
            //根据系统当前日期查找到对应的年周期
            DataTable _year = dllQuarterDateManager.getQuarterDate();
            this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_year.Rows[0][2].ToString()));

            if (Request.Params["Id"] != null && Request.Params["Id"].ToString().Length != 0)
            {
                object[] _monthDate = new object[1];
                _monthDate[0] = Convert.ToInt32(Request.Params["Id"].ToString());
                DataTable _monthDateTable = dllMonthDateManager.get(MonthDateManager.field.Month_Id.ToString(), _monthDate);
                if (_monthDateTable.Rows.Count > 0)
                {
                    this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_monthDateTable.Rows[0]["MonthYear"].ToString()));
                }
            }
        }

        //绑定年计划周期
        if (_drp.Equals(this.drpQuarterDate))
        {
            object[] _value = new object[1];
            _value[0] = this.drpYear.SelectedValue;
            DataTable _quarter = dllQuarterDateManager.get(QuarterDateManager.field.QuarterYear.ToString(), _value);
            if (_quarter.Rows.Count != 0)
            {
                this.drpQuarterDate.DataSource = _quarter;
                this.drpQuarterDate.DataTextField = "QuarterName";
                this.drpQuarterDate.DataValueField = "Quarter_Id";
                this.drpQuarterDate.DataBind();
                #region dropdownlist显示系统所对应的当前年周期
                //根据系统当前日期查找到对应的年周期
                DataTable _quartertime = dllQuarterDateManager.getQuarterDate();
                //如果查到结果（结果只有一条）
                if (_quartertime.Rows.Count > 0)
                {
                    this.drpQuarterDate.SelectedIndex = this.drpQuarterDate.Items.IndexOf(this.drpQuarterDate.Items.FindByText(_quartertime.Rows[0][1].ToString()));
                    if (Request.Params["Id"] != null && Request.Params["Id"].ToString().Length != 0)
                    {
                        object[] _monthDate = new object[1];
                        _monthDate[0] = Convert.ToInt32(Request.Params["Id"].ToString());
                        DataTable _monthDateTable = dllMonthDateManager.get(MonthDateManager.field.Month_Id.ToString(), _monthDate);
                        if (_monthDateTable.Rows.Count > 0)
                        {
                            this.drpQuarterDate.SelectedIndex = this.drpQuarterDate.Items.IndexOf(this.drpQuarterDate.Items.FindByText(_monthDateTable.Rows[0]["QuarterName"].ToString()));
                        }
                    }
                }
                #endregion
                bindDropDownList(this.drpMonthDate);
            }
            else
            {
                ListItem _li = new ListItem("无年周期", "0");
                this.drpQuarterDate.Items.Clear();
                this.drpQuarterDate.Items.Add(_li);
                bindDropDownList(this.drpMonthDate);
            }

        }

        //绑定月计划周期
        if (_drp.Equals(this.drpMonthDate))
        {
            object[] _value = new object[2];
            _value[0] = this.drpYear.SelectedValue;
            _value[1] = this.drpQuarterDate.SelectedItem.Text;
            DataTable _month = dllMonthDateManager.get(MonthDateManager.field.QuarterName.ToString(), _value);
            if (_month.Rows.Count != 0)
            {
                this.drpMonthDate.DataSource = _month;
                this.drpMonthDate.DataTextField = "MonthName";
                this.drpMonthDate.DataValueField = "Month_Id";
                this.drpMonthDate.DataBind();
                #region 根据系统当前日期绑定到当前月周期
                DataTable _monthtime = dllMonthDateManager.getMonthDate();
                if (_monthtime.Rows.Count > 0)
                {
                    this.drpMonthDate.SelectedIndex = this.drpMonthDate.Items.IndexOf(this.drpMonthDate.Items.FindByText(_monthtime.Rows[0][3].ToString()));
                    if (Request.Params["Id"] != null && Request.Params["Id"].ToString().Length != 0)
                    {
                        this.drpMonthDate.SelectedIndex = this.drpMonthDate.Items.IndexOf(this.drpMonthDate.Items.FindByValue(Request.Params["Id"].ToString()));
                    }
                }
                bindGridView(this.gdvMonthList);
                bindGridView(this.gdvPreMonthList);
                bindGridView(this.gdvPreNoCompeleteMonthPlan);
                bindGridView(this.gdvContinueMonthList);

                #endregion

            }
            else
            {
                ListItem _li = new ListItem("无月周期", "0");
                this.drpMonthDate.Items.Clear();
                this.drpMonthDate.Items.Add(_li);
                bindGridView(this.gdvMonthList);
                bindGridView(this.gdvPreMonthList);
                bindGridView(this.gdvPreNoCompeleteMonthPlan);
                bindGridView(this.gdvContinueMonthList);
            }
        }
    }



    /// <summary>
    /// 绑定月提醒
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-3-9</date>
    void BindMonthRemind()
    {
        TheMonthRemind = "";
        PreMonthRemind = "";
        ListItem _li = this.drpDepartment.SelectedItem;
        if (_li != null)
        {
            if (_li.Text != null && _li.Text != "请选择部门")
            {
                object[] _value = new object[2];
                _value[0] = _li.Text;
                _value[1] = Convert.ToInt32(this.drpMonthDate.SelectedValue);
                //根据用户所在部门和当前时间查询本月上月工作提醒
                DataTable _preMonthRemind = dllMonth_RemindofManager.getPreMonthRemind(_value);
                DataTable _theMonthRemind = dllMonth_RemindofManager.getTheMonthRemind(_value);
                if (_preMonthRemind.Rows.Count > 0)
                {
                    for (int i = 0; i < _preMonthRemind.Rows.Count; i++)
                    {
                        int num = i + 1;
                        PreMonthRemind += num + ":" + _preMonthRemind.Rows[i]["TheMonthRemind"].ToString() + "\r\n";
                    }
                }
                this.lblPreMonthRemind.Text = PreMonthRemind;
                if (_theMonthRemind.Rows.Count > 0)
                {
                    for (int i = 0; i < _theMonthRemind.Rows.Count; i++)
                    {
                        int num = i + 1;
                        TheMonthRemind += num + ":" + _theMonthRemind.Rows[i]["TheMonthRemind"].ToString() + "\r\n";
                    }
                }
                this.lblTheMonthRemind.Text = TheMonthRemind;
            }
        }
    }

    //构建上月计划表结构并添加1行
    DataTable createDataTable()
    {
        DataTable _dt = new DataTable();
        DataColumn dc = new DataColumn("MonthPlanSortId");
        _dt.Columns.Add(dc);
        dc = new DataColumn("WorkItem");
        _dt.Columns.Add(dc);
        dc = new DataColumn("Source");
        _dt.Columns.Add(dc);
        dc = new DataColumn("CompleteTime");
        _dt.Columns.Add(dc);
        dc = new DataColumn("MasterPeople");
        _dt.Columns.Add(dc);
        dc = new DataColumn("SlaveDepartment");
        _dt.Columns.Add(dc);
        dc = new DataColumn("SlaveDepartmentDuty");
        _dt.Columns.Add(dc);
        dc = new DataColumn("EvaluatePeople");
        _dt.Columns.Add(dc);
        dc = new DataColumn("PlanSendState");
        _dt.Columns.Add(dc);
        dc = new DataColumn("CheckNote");
        _dt.Columns.Add(dc);
        dc = new DataColumn("Remart");
        _dt.Columns.Add(dc);
        dc = new DataColumn("QuarterPlanId");
        _dt.Columns.Add(dc);
        dc = new DataColumn("AttachmentPath");
        _dt.Columns.Add(dc);
        dc = new DataColumn("NoCompleteCount");
        _dt.Columns.Add(dc);
        dc = new DataColumn("MonthPlanId");
        _dt.Columns.Add(dc);
        dc = new DataColumn("PlanStep");
        _dt.Columns.Add(dc);
        dc = new DataColumn("VerifyPeopleOpinion");
        _dt.Columns.Add(dc);
        DataRow dr = _dt.NewRow();
        dr["MonthPlanSortId"] = "";
        dr["WorkItem"] = "";
        dr["Source"] = "";
        dr["CompleteTime"] = "";
        dr["MasterPeople"] = "";
        dr["SlaveDepartment"] = "";
        dr["SlaveDepartmentDuty"] = "";
        dr["EvaluatePeople"] = "";
        dr["PlanSendState"] = "0";
        dr["CheckNote"] = "";
        dr["Remart"] = "";
        dr["QuarterPlanId"] = "";
        dr["NoCompleteCount"] = "";
        dr["AttachmentPath"] = "";
        dr["MonthPlanId"] = "";
        dr["PlanStep"] = "";
        dr["VerifyPeopleOpinion"] = "";
        _dt.Rows.Add(dr);
        return _dt;
    }

    //构建上月总结
    DataTable createMonthSummary()
    {
        DataTable _dt = new DataTable();
        DataColumn dc = new DataColumn("PreMonthSummary");
        _dt.Columns.Add(dc);
        dc = new DataColumn("MonthSummary");
        _dt.Columns.Add(dc);
        dc = new DataColumn("AttachmentPath");
        _dt.Columns.Add(dc);
        dc = new DataColumn("Id");
        _dt.Columns.Add(dc);
        DataRow dr = _dt.NewRow();
        dr["PreMonthSummary"] = "";
        dr["MonthSummary"] = "";
        dr["AttachmentPath"] = "";
        dr["Id"] = "";
        _dt.Rows.Add(dr);
        return _dt;
    }

    /// <summary>
    /// 绑定gridview事件
    /// </summary>
    void bindGridView(GridView _gridView)
    {
        if (_gridView.Equals(this.gdvPreMonthList))
        {
            #region 绑定上月计划
            this.gdvPreMonthList.DataSource = new DataTable();
            this.gdvPreMonthList.DataBind();
            //得到用户名
            Model.UserInfo _objUserInfo = new Model.UserInfo();
            object[] _value = new object[3];
            _value[0] = Convert.ToInt32(this.drpMonthDate.SelectedValue);
            _value[1] = _objUserInfo.UserName;
            _value[2] = this.drpDepartment.SelectedItem.Text;
            DataSet _monthPlan = dllMonthPlanManager.getPreMonthPlan(_value);
            if (_monthPlan.Tables.Count > 1)
            {
                for (int j = 1; j < _monthPlan.Tables.Count; j++)
                {
                    if (_monthPlan.Tables[j].Rows.Count > 0)
                    {
                        DataView dv = new DataView(_monthPlan.Tables[j]);
                        dv.Sort = "MonthPlanSortId";
                        this.gdvPreMonthList.DataSource = dv;
                        this.gdvPreMonthList.DataBind();
                    }
                }

                #region
                //for (int i = 0; i < gdvPreMonthList.Rows.Count; i++)
                //{
                //    //文件下载，判断如果下载了就显示《下载按钮》 反之 就显示“无下载”
                //    if (gdvPreMonthList.DataKeys[i]["AttachmentPath"].ToString().Length == 0)
                //    {
                //        Button _btn = (Button)gdvPreMonthList.Rows[i].Cells[12].FindControl("btnDownLoad");
                //        _btn.Visible = false;
                //        Label _lbl = (Label)gdvPreMonthList.Rows[i].Cells[12].FindControl("lblAlert");
                //        _lbl.Visible = true;
                //        _lbl.Text = "无下载";
                //    }
                //}

                #endregion

            }
            if (this.gdvPreMonthList.Rows.Count == 0)
            {
                this.gdvPreMonthList.DataSource = createDataTable();
                this.gdvPreMonthList.DataBind();
            }

            #endregion
            processGridViewPre(_gridView);
            setUploadfile(gdvPreMonthList, "btnDownLoad", "lblAlert");
        }
        //绑定月总结
        if (_gridView.Equals(this.gdvPreMonthList))
        {
            object[] _valueSummary = new object[2];
            _valueSummary[0] = Convert.ToInt32(this.drpMonthDate.SelectedValue);
            _valueSummary[1] = this.drpDepartment.SelectedItem.Text;
            DataTable dt = new BLL.MonthSummary().get(BLL.MonthSummary.field.MonthDate.ToString(), BLL.MonthSummary.field.Department.ToString(), _valueSummary);
            if (dt.Rows.Count > 0)
            {
                this.txtMonthSummary.Text = dt.Rows[0]["MonthSummary"].ToString();
                this.txtWorkItemfinish.Text = dt.Rows[0]["WrokItemFinished"].ToString();
                this.txtWorkItemunfinish.Text = dt.Rows[0]["WrokItemUnFinished"].ToString();
                this.txtfinishdetail.Text = dt.Rows[0]["FinishDetail"].ToString();
                this.txtimprovement.Text = dt.Rows[0]["Improvement"].ToString();
                this.txtreason.Text = dt.Rows[0]["UnFinishReason"].ToString();
                this.txtCreatecontent.Text = dt.Rows[0]["CreateDetail"].ToString();
                //this.txtPreMonthSummary.Text = dt.Rows[0]["PreMonthSummary"].ToString();
                //this.prelength.InnerHtml = this.txtPreMonthSummary.Text.Length.ToString();
                this.thelength.InnerHtml = this.txtMonthSummary.Text.Length.ToString();
                this.HMonthSummaryId.Value = dt.Rows[0]["Id"].ToString();
                //this.HPreAttachmentPath.Value = dt.Rows[0]["PreAttachmentPath"].ToString();
                this.HAttachmentPath.Value = dt.Rows[0]["AttachmentPath"].ToString();

            }
            else
            {
                //this.txtPreMonthSummary.Text = "注：工作总结不少于3条，总字数不少于60个字。";
                this.txtMonthSummary.Text = "注：工作部署不少于3条，总字数不少于60个字。";
                //this.prelength.InnerHtml = "0";
                this.thelength.InnerHtml = "0";
                //this.HMonthSummaryId.Value = string.Empty;
                //this.HPreAttachmentPath.Value = string.Empty;
                this.HAttachmentPath.Value = string.Empty;
            }
            if (this.txtMonthSummary.Text.Length > 0 && this.txtMonthSummary.Text != "注：工作部署不少于3条，总字数不少于60个字。")
            {
                this.btnAddMonthSummary.Text = "修改";
            }
            else
            {
                this.btnAddMonthSummary.Text = "添加";
            }
            if (this.txtWorkItemfinish.Text.Length > 0 || this.txtWorkItemunfinish.Text.Length > 0)
            {
                this.btnAddPreMonthSummary.Text = "修改";
            }
            else
            {
                this.btnAddPreMonthSummary.Text = "添加";
            }

            if (this.HAttachmentPath.Value.Length > 0)
            {
                this.btnDownMonthSummary.Enabled = true;
            }
            else
            {
                this.btnDownMonthSummary.Enabled = false;
            }
            if (objUserInfo.UserName != "admin")
            {
                bool Isdepartment = false;
                //当前部门并且当前月份
                object[] _value = new object[1];
                _value[0] = objUserInfo.UserName;
                DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _value);
                if (_userTable.Rows.Count > 0)
                {
                    if (_userTable.Rows[0]["DepartmentId"].ToString() == this.drpDepartment.SelectedItem.Text || _userTable.Rows[0]["PartTimeDepartmentId"].ToString() == this.drpDepartment.SelectedItem.Text)
                    {
                        Isdepartment = true;
                    }
                }

                bool IsDate = new BLL.MonthDateManager().IsEditMonthSummary(new object[] { Convert.ToInt32(this.drpMonthDate.SelectedValue) });
                //DataTable _monthtime = dllMonthDateManager.getMonthDate();
                //if (this.drpMonthDate.SelectedItem.Text == _monthtime.Rows[0][3].ToString())
                //{
                //    IsDate = true;

                //}
                if (Isdepartment && IsDate)
                {
                    this.btnAddPreMonthSummary.Enabled = true;
                    this.btnAddMonthSummary.Enabled = true;
                    this.btnUploadMonthSummary.Enabled = true;
                    //this.btnUploadPreMonthSummary.Enabled = true;
                }
                else
                {
                    this.btnAddPreMonthSummary.Enabled = false;
                    this.btnAddMonthSummary.Enabled = false;
                    this.btnUploadMonthSummary.Enabled = false;
                    //this.btnUploadPreMonthSummary.Enabled = false;
                }
                this.btnSaveMonthSummary.Visible = false;
                this.btnSavePreMonthSummary.Visible = false;
                this.btnAddMonthSummary.Visible = true;
                this.btnAddPreMonthSummary.Visible = true;
            }
            //this.txtMonthSummary.Attributes.Add("readonly", "true");
            //this.txtPreMonthSummary.Attributes.Add("readonly", "true");
            this.txtMonthSummary.ReadOnly = true;
            //this.txtPreMonthSummary.ReadOnly = true;
        }
        if (_gridView.Equals(this.gdvMonthList))
        {
            #region 绑定本月计划
            this.gdvMonthList.DataSource = new DataTable();
            this.gdvMonthList.DataBind();
            //得到用户名
            Model.UserInfo _objUserInfo = new Model.UserInfo();
            object[] _value = new object[3];
            _value[0] = Convert.ToInt32(this.drpMonthDate.SelectedValue);
            _value[1] = _objUserInfo.UserName;
            _value[2] = this.drpDepartment.SelectedItem.Text;
            DataSet _monthPlan = dllMonthPlanManager.getMonthPlan(_value);
            if (_monthPlan.Tables.Count > 1)
            {
                for (int j = 1; j < _monthPlan.Tables.Count; j++)
                {
                    if (_monthPlan.Tables[j].Rows.Count > 0)
                    {
                        DataView dv = new DataView(_monthPlan.Tables[j]);
                        dv.Sort = "MonthPlanSortId";
                        this.gdvMonthList.DataSource = dv;
                        this.gdvMonthList.DataBind();
                    }
                }
            }
            if (this.gdvMonthList.Rows.Count == 0)
            {
                this.gdvMonthList.DataSource = createDataTable();
                this.gdvMonthList.DataBind();
            }

            #endregion
            processGridViewForMonth(_gridView);
            setUploadfile(gdvMonthList, "btndown2", "lblAlert2");
        }
        if (_gridView.Equals(this.gdvPreNoCompeleteMonthPlan))
        {
            #region 绑定上月未完成计划
            this.gdvPreNoCompeleteMonthPlan.DataSource = new DataTable();
            this.gdvPreNoCompeleteMonthPlan.DataBind();
            //得到用户名
            Model.UserInfo _objUserInfo = new Model.UserInfo();
            object[] _value = new object[3];
            _value[0] = Convert.ToInt32(this.drpMonthDate.SelectedValue);
            _value[1] = _objUserInfo.UserName;
            _value[2] = this.drpDepartment.SelectedItem.Text;
            DataSet _monthPlan = dllMonthPlanManager.getPreMonthPlanNoComplete(_value);
            if (_monthPlan.Tables.Count > 1)
            {
                for (int j = 1; j < _monthPlan.Tables.Count; j++)
                {
                    if (_monthPlan.Tables[j].Rows.Count > 0)
                    {
                        DataView dv = new DataView(_monthPlan.Tables[j]);
                        dv.Sort = "MonthPlanSortId";
                        this.gdvPreNoCompeleteMonthPlan.DataSource = dv;
                        this.gdvPreNoCompeleteMonthPlan.DataBind();
                    }
                }
            }
            if (this.gdvPreNoCompeleteMonthPlan.Rows.Count == 0)
            {
                this.gdvPreNoCompeleteMonthPlan.DataSource = createDataTable();
                this.gdvPreNoCompeleteMonthPlan.DataBind();
            }

            #endregion
            processGridView(_gridView);
            setUploadfile(gdvPreNoCompeleteMonthPlan, "btndown3", "lblAlert3");
        }
        if (_gridView.Equals(this.gdvContinueMonthList))
        {
            #region 绑定上月持续计划
            this.gdvContinueMonthList.DataSource = new DataTable();
            this.gdvContinueMonthList.DataBind();
            //得到用户名
            Model.UserInfo _objUserInfo = new Model.UserInfo();
            object[] _value = new object[3];
            _value[0] = Convert.ToInt32(this.drpMonthDate.SelectedValue);
            _value[1] = _objUserInfo.UserName;
            _value[2] = this.drpDepartment.SelectedItem.Text;
            DataSet _monthPlan = dllMonthPlanManager.getMonthPlanContinue(_value);
            if (_monthPlan.Tables.Count > 1)
            {
                for (int j = 1; j < _monthPlan.Tables.Count; j++)
                {
                    if (_monthPlan.Tables[j].Rows.Count > 0)
                    {
                        DataView dv = new DataView(_monthPlan.Tables[j]);
                        dv.Sort = "MonthPlanSortId";
                        this.gdvContinueMonthList.DataSource = dv;
                        this.gdvContinueMonthList.DataBind();
                    }
                }
            }

            if (this.gdvContinueMonthList.Rows.Count == 0)
            {
                this.gdvContinueMonthList.DataSource = createDataTable();
                this.gdvContinueMonthList.DataBind();
            }

            #endregion
            processGridViewForMonth(_gridView);
            setUploadfile(gdvContinueMonthList, "btndown4", "lblAlert4");
        }
        #region    截取字符串

        //processGridView(_gridView);
        #endregion



    }

    void setUploadfile(GridView objgv, string btnname, string lblname)
    {
        #region
        for (int i = 0; i < objgv.Rows.Count; i++)
        {
            //文件下载，判断如果下载了就显示《下载按钮》 反之 就显示“无下载”
            if (objgv.DataKeys[i]["AttachmentPath"].ToString().Length == 0)
            {
                Button _btn = (Button)objgv.Rows[i].FindControl(btnname);
                _btn.Visible = false;
                Label _lbl = (Label)objgv.Rows[i].FindControl(lblname);
                _lbl.Visible = true;
                _lbl.Text = "无下载";
            }
        }

        #endregion
    }

    /// <summary>
    /// 根据逗号换行事件
    /// </summary>
    void wrapByComma(GridView _gridView, int _rowIndex, int _cells)
    {
        string _content = _gridView.Rows[_rowIndex].Cells[_cells].Text;
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&lt;br&gt;", "<br>");
        //_gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&gt;", ">");
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _gridView.Rows[_rowIndex].Cells[_cells].Text.Replace(",", "<br>");


    }


    /// <summary>
    /// 处理日期和来源显示以及根据逗号换行
    /// </summary>
    /// <param name="_gridView"></param>
    void processGridView(GridView _gridView)
    {
        for (int i = 0; i < _gridView.Rows.Count; i++)
        {
            LinkButton lbtn = (LinkButton)_gridView.Rows[i].Cells[4].FindControl("lbtnSource");
            lbtn.Text = _gridView.DataKeys[i]["Source"].ToString();
            //gridview的第六和七行，根据逗号换行
            wrapByComma(_gridView, i, 7);

            wrapByComma(_gridView, i, 8);

            if (_gridView.DataKeys[i]["PlanSendState"] != "&nbsp;" && _gridView.DataKeys[i]["PlanSendState"] != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            {
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 4)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C0C0");
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C000");
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Yellow;
                }

                //判断2次以上变红为失控状态
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                //失控标红
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 7)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                //计划调整变灰
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 8)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Gray;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1
                    || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2
                    || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 9)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
                }
                //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
                //{
                //    _gridView.Rows[i].Cells[10].Text = "达成共识<br/>" + _gridView.Rows[i].Cells[10].Text;
                //}
                //else
                //{
                //    _gridView.Rows[i].Cells[10].Text = "";
                //}
            }
            if (_gridView.Rows[i].Cells[8].Text == "&nbsp;" || _gridView.Rows[i].Cells[8].Text == "&amp;nbsp;")
            {
                _gridView.Rows[i].Cells[8].Text = "";
            }
            //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 0)
            //{
            //    _gridView.Rows[i].Cells[10].Text = "";
            //}

            #region 2010-06-03修改达成共识与评估意见合并注释
            //if (_gridView.Rows[i].Cells[11].Text != "&nbsp;" && _gridView.Rows[i].Cells[11].Text != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            //{
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 4)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C0C0");
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C000");
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Yellow;
            //    }

            //    //判断2次以上变红为失控状态
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    //失控标红
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 7)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1 || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2 )
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].Cells[11].Text = "达成共识";
            //    }
            //    else
            //    {
            //        _gridView.Rows[i].Cells[11].Text = "";
            //    }
            //}
            //if (_gridView.Rows[i].Cells[12].Text == "&nbsp;" || _gridView.Rows[i].Cells[12].Text == "&amp;nbsp;")
            //{
            //    _gridView.Rows[i].Cells[12].Text = "";
            //}
            //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 0)
            //{
            //    _gridView.Rows[i].Cells[11].Text = "";
            //}
            #endregion
        }
    }


    /// <summary>
    /// 处理日期和来源显示以及根据逗号换行
    /// </summary>
    /// <param name="_gridView"></param>
    void processGridViewPre(GridView _gridView)
    {
        for (int i = 0; i < _gridView.Rows.Count; i++)
        {
            LinkButton lbtn = (LinkButton)_gridView.Rows[i].Cells[4].FindControl("lbtnSource");
            lbtn.Text = _gridView.DataKeys[i]["Source"].ToString();
            //gridview的第六和七行，根据逗号换行
            wrapByComma(_gridView, i, 7);

            wrapByComma(_gridView, i, 8);

            if (_gridView.DataKeys[i]["PlanSendState"] != "&nbsp;" && _gridView.DataKeys[i]["PlanSendState"] != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            {
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 4)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C0C0");
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C000");
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Yellow;
                }

                //判断2次以上变红为失控状态
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                //失控标红
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 7)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
                }
                //计划调整变灰
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 8)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Gray;
                }
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1
                    || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2
                    || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 9)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
                }
                //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
                //{
                //    _gridView.Rows[i].Cells[11].Text = "达成共识<br/>" + _gridView.Rows[i].Cells[11].Text;
                //}
                //else
                //{
                //    _gridView.Rows[i].Cells[11].Text = "";
                //}
            }
            if (_gridView.Rows[i].Cells[8].Text == "&nbsp;" || _gridView.Rows[i].Cells[8].Text == "&amp;nbsp;")
            {
                _gridView.Rows[i].Cells[8].Text = "";
            }
            //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 0)
            //{
            //    _gridView.Rows[i].Cells[11].Text = "";
            //}

            #region 2010-06-03修改达成共识与评估意见合并注释
            //if (_gridView.Rows[i].Cells[10].Text != "&nbsp;" && _gridView.Rows[i].Cells[10].Text != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            //{
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 4)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C0C0");
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.FromName("#00C000");
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Yellow;
            //    }

            //    //判断2次以上变红为失控状态
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 5 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 6 && Convert.ToInt32(_gridView.DataKeys[i]["NoCompleteCount"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    //失控标红
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 7)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Red;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1 || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].Cells[10].Text = "达成共识";
            //    }
            //    else
            //    {
            //        _gridView.Rows[i].Cells[10].Text = "";
            //    }
            //}
            //if (_gridView.Rows[i].Cells[11].Text == "&nbsp;" || _gridView.Rows[i].Cells[11].Text == "&amp;nbsp;")
            //{
            //    _gridView.Rows[i].Cells[11].Text = "";
            //}
            //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 0)
            //{
            //    _gridView.Rows[i].Cells[10].Text = "";
            //}
            #endregion
        }
    }

    /// <summary>
    /// 处理日期和来源显示以及根据逗号换行
    /// </summary>
    /// <param name="_gridView"></param>
    void processGridViewForMonth(GridView _gridView)
    {
        for (int i = 0; i < _gridView.Rows.Count; i++)
        {
            LinkButton lbtn = (LinkButton)_gridView.Rows[i].Cells[4].FindControl("lbtnSource");
            lbtn.Text = _gridView.DataKeys[i]["Source"].ToString();
            //gridview的第六和七行，根据逗号换行
            wrapByComma(_gridView, i, 7);
            wrapByComma(_gridView, i, 8);

            if (_gridView.DataKeys[i]["PlanSendState"] != "&nbsp;" && _gridView.DataKeys[i]["PlanSendState"] != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            {


                //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
                //{
                //    _gridView.Rows[i].Cells[10].Text = "达成共识<br/>" + _gridView.Rows[i].Cells[10].Text;
                //}
                //else
                //{
                //    _gridView.Rows[i].Cells[10].Text = "";
                //}
                if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1
                    || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2
                    || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 9)
                {
                    _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
                }
            }
            if (_gridView.Rows[i].Cells[8].Text == "&nbsp;" || _gridView.Rows[i].Cells[8].Text == "&amp;nbsp;")
            {
                _gridView.Rows[i].Cells[8].Text = "";
            }
            //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 0)
            //{
            //    _gridView.Rows[i].Cells[10].Text = "";
            //}

            #region 2010-06-03修改达成共识与评估意见合并注释
            //if (_gridView.Rows[i].Cells[11].Text != "&nbsp;" && _gridView.Rows[i].Cells[11].Text != "" && _gridView.DataKeys[i]["NoCompleteCount"].ToString() != "")
            //{


            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) > 2)
            //    {
            //        _gridView.Rows[i].Cells[11].Text = "达成共识";
            //    }
            //    else
            //    {
            //        _gridView.Rows[i].Cells[11].Text = "";
            //    }
            //    if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 1 || Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 2)
            //    {
            //        _gridView.Rows[i].BackColor = System.Drawing.Color.Pink;
            //    }
            //}
            //if (_gridView.Rows[i].Cells[12].Text == "&nbsp;" || _gridView.Rows[i].Cells[12].Text == "&amp;nbsp;")
            //{
            //    _gridView.Rows[i].Cells[12].Text = "";
            //}
            //if (Convert.ToInt32(_gridView.DataKeys[i]["PlanSendState"].ToString()) == 0)
            //{
            //    _gridView.Rows[i].Cells[11].Text = "";
            //}
            #endregion
        }
    }

    /// <summary>
    /// 来源年计划链接事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnSource_Click(object sender, EventArgs e)
    {
        int i = 0;
        LinkButton bt = (LinkButton)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        Control c = (Control)iRow.Parent;
        GridView _gdv = (GridView)c.Parent;
        //判断是否年计划分解而来还是年计划分解计划分解而来
        //if (_gdv.DataKeys[i]["Source"].ToString().Contains("."))
        //{
        int _quarterPlanId = Convert.ToInt32(_gdv.DataKeys[i]["QuarterPlanId"].ToString());
        if (_quarterPlanId == 0)
        {
            //新增的月计划，不需要跳转到指定页面
        }
        else
        {
            string _url = "/WebCommon/DisplaySource.aspx?PlanId=" + _quarterPlanId + "&type=Month";
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','newwindow','height=500,width=900,top=200,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }
        //}
        //else
        //{
        //    int _quarterPlanId = Convert.ToInt32(_gdv.DataKeys[i]["QuarterPlanId"].ToString());
        //    if (_quarterPlanId == 0)
        //    {
        //        //新增的月计划，不需要跳转到指定页面
        //    }
        //    else
        //    {
        //        string _url = "QuarterPlanDetail.aspx?QuarterPlanId=" + _quarterPlanId;
        //        Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','newwindow','height=200,width=900,top=200,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        //    }
        //}
    }


    /// <summary>
    /// 部门项改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpDepartment_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.drpDepartment.SelectedItem != null && this.drpDepartment.SelectedItem.Text != "请选择部门")
        {
            bindGridView(this.gdvMonthList);
            bindGridView(this.gdvPreMonthList);
            bindGridView(this.gdvPreNoCompeleteMonthPlan);
            bindGridView(this.gdvContinueMonthList);
            BindMonthRemind();
            object[] _value = new object[1];
            _value[0] = objUserInfo.UserName;
            DataTable _userTable = dllUserInfoManager.get(UserInfoManager.field.UserName.ToString(), _value);
            if (_userTable.Rows.Count > 0)
            {
                if (this.drpDepartment.SelectedItem.Text != _userTable.Rows[0]["DepartmentId"].ToString()
                    && objUserInfo.UserName != "admin"
                    && this.drpDepartment.SelectedItem.Text != _userTable.Rows[0]["PartTimeDepartmentId"].ToString()
                    && !_userTable.Rows[0]["RoleName"].ToString().Contains("总监"))
                {
                    //this.btnResolve.Visible = false;
                    this.btnModifyContinue.Visible = false;
                    this.btnModifyMonth.Visible = false;
                    this.btnModifyPrevMonth.Visible = false;
                    this.btnMonthResolve.Visible = false;
                    this.btnResolveToUserMonthPlan.Visible = false;
                }
                else
                {
                    // this.btnResolve.Visible = true;
                    this.btnModifyContinue.Visible = true;
                    this.btnModifyMonth.Visible = true;
                    this.btnModifyPrevMonth.Visible = true;
                    this.btnMonthResolve.Visible = true;
                    this.btnResolveToUserMonthPlan.Visible = true;
                }
            }
        }
        this.btnAddMonthSummary.Visible = true;
        this.btnAddPreMonthSummary.Visible = true;
        this.btnSaveMonthSummary.Visible = false;
        this.btnSavePreMonthSummary.Visible = false;
    }


    /// <summary>
    /// 投影显示事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDisplay_Click(object sender, EventArgs e)
    {
        string department = drpDepartment.SelectedItem.Value;

        string _height = this.h1h.Value;
        string _width = this.h2w.Value;
        string _url = "MonthPlanDisplay.aspx?Id=" + Convert.ToInt32(this.drpMonthDate.SelectedValue) + "&depart=" + department + "&Year=" + this.drpYear.SelectedValue + "&Quarter=" + this.drpQuarterDate.SelectedValue + "&Month=" + this.drpMonthDate.SelectedValue;
        Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','newwindow','height= " + _height + ",width=" + _width + ",top=0,left=0,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
    }


    /// <summary>
    /// 下载附件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDownLoad_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列
        string path = this.gdvPreMonthList.DataKeys[i]["AttachmentPath"].ToString();
        FileDownload(path);
        //Utility.HttpHelp.DownloadFile(path);
    }
    /// <summary>
    /// 本月下载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btndown2_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列
        string path = this.gdvMonthList.DataKeys[i]["AttachmentPath"].ToString();
        FileDownload(path);
        //Utility.HttpHelp.DownloadFile(path);
    }
    /// <summary>
    /// 上月未完成工作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btndown3_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列
        string path = this.gdvPreNoCompeleteMonthPlan.DataKeys[i]["AttachmentPath"].ToString();
        FileDownload(path);
        //Utility.HttpHelp.DownloadFile(path);
    }
    /// <summary>
    /// 持续计划下载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btndown4_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列
        string path = this.gdvContinueMonthList.DataKeys[i]["AttachmentPath"].ToString();
        FileDownload(path);
        //Utility.HttpHelp.DownloadFile(path);
    }

    ///   <summary>   
    ///   文件下载   
    ///   </summary>   
    ///   <param   name="FullFileName"></param>   
    private void FileDownload(string strFileName)
    {

        FileInfo DownloadFile = new FileInfo(strFileName);
        if (!DownloadFile.Exists)
        {
            Utility.HttpHelp.alert("无附件,请与管理员联系", Page);
            return;
        }
        Response.Clear();
        Response.ClearHeaders();
        Response.Buffer = false;
        Response.ContentType = "application/octet-stream";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName.Substring(strFileName.LastIndexOf('\\') + 1), System.Text.Encoding.UTF8));
        // Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());

        Response.WriteFile(DownloadFile.FullName);
        Response.Flush();
        Response.End();

    }


    /// <summary>
    /// 年份改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpQuarterDate);
        bindDropDownList(this.drpMonthDate);
    }

    /// <summary>
    /// 年周期改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpQuarterDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpMonthDate);
        this.btnAddMonthSummary.Visible = true;
        this.btnAddPreMonthSummary.Visible = true;
        this.btnSaveMonthSummary.Visible = false;
        this.btnSavePreMonthSummary.Visible = false;
        IsManager();
    }


    /// <summary>
    /// 月周期改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpMonthDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindGridView(this.gdvMonthList);
        bindGridView(this.gdvPreMonthList);
        bindGridView(this.gdvPreNoCompeleteMonthPlan);
        bindGridView(this.gdvContinueMonthList);
        BindMonthRemind();
        this.btnAddMonthSummary.Visible = true;
        this.btnAddPreMonthSummary.Visible = true;
        this.btnSaveMonthSummary.Visible = false;
        this.btnSavePreMonthSummary.Visible = false;
        IsManager();
    }



    /// <summary>
    /// 导出excel
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnToExcel_Click(object sender, EventArgs e)
    {
        GridView[] _gridView = new GridView[4];
        _gridView[0] = this.gdvPreMonthList;
        _gridView[1] = this.gdvMonthList;
        _gridView[2] = this.gdvPreNoCompeleteMonthPlan;
        _gridView[3] = this.gdvContinueMonthList;
        Utility.Comm.MonthToExcel(GridViewToDataTable(_gridView), this.drpDepartment.SelectedItem.Text, this.drpQuarterDate.SelectedItem.Text + this.drpMonthDate.SelectedItem.Text, this.lblPreMonthRemind.Text, this.lblTheMonthRemind.Text);
    }



    /// <summary>
    /// GridView转DataTable
    /// </summary>
    DataTable[] GridViewToDataTable(GridView[] _sourceGridView)
    {
        DataTable[] _targetDataTable = new DataTable[_sourceGridView.Length];
        for (int i = 0; i < _targetDataTable.Length; i++)
        {
            _targetDataTable[i] = new DataTable();
            DataColumn dc = new DataColumn();
            //根据源GridView循环创建目标DataTable列
            for (int j = 0; j < _sourceGridView[i].Columns.Count; j++)
            {
                if (_sourceGridView[i].Columns[j].Visible == true)
                {
                    dc = new DataColumn(_sourceGridView[i].Columns[j].HeaderText);
                    _targetDataTable[i].Columns.Add(dc);
                }
            }
            //根据源GridView循环创建目标DataTable行
            for (int j = 0; j < _sourceGridView[i].Rows.Count; j++)
            {
                DataRow dr = _targetDataTable[i].NewRow();
                for (int k = 0; k < _sourceGridView[i].Columns.Count; k++)
                {

                    if (_sourceGridView[i].Columns[k].Visible == true && k < _targetDataTable[i].Columns.Count)
                    {
                        if (_sourceGridView[i].Columns[k].HeaderText == "计划来源")
                        {
                            LinkButton lbtn = (LinkButton)_sourceGridView[i].Rows[j].Cells[k].FindControl("lbtnSource");
                            dr[k] = lbtn.Text;
                        }
                        else
                        {
                            dr[k] = _sourceGridView[i].Rows[j].Cells[k].Text;
                        }

                    }

                }
                _targetDataTable[i].Rows.Add(dr);
            }

        }
        return _targetDataTable;
    }


    /// <summary>
    /// 流程事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnFlow_Click(object sender, EventArgs e)
    {
        int _count = 0;
        int _monthId = 0;
        int type = -1;//1 上月工作情况 2 本月工作情况 3上月未完成工作  4 持续进行工作
        //上月工作情况
        for (int i = 0; i < this.gdvPreMonthList.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvPreMonthList.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvPreMonthList.DataKeys[i]["MonthPlanId"] != null && this.gdvPreMonthList.DataKeys[i]["MonthPlanId"].ToString().Length != 0)
                {
                    _monthId = Convert.ToInt32(this.gdvPreMonthList.DataKeys[i]["MonthPlanId"].ToString());
                    _count++;
                    type = 1;
                }
            }
        }
        //本月工作情况
        for (int i = 0; i < this.gdvMonthList.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvMonthList.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvMonthList.DataKeys[i]["MonthPlanId"] != null && this.gdvMonthList.DataKeys[i]["MonthPlanId"].ToString().Length != 0)
                {
                    _monthId = Convert.ToInt32(this.gdvMonthList.DataKeys[i]["MonthPlanId"].ToString());
                    _count++;
                    type = 2;
                }
            }
        }
        //上月未完成工作
        for (int i = 0; i < this.gdvPreNoCompeleteMonthPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvPreNoCompeleteMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvPreNoCompeleteMonthPlan.DataKeys[i]["MonthPlanId"] != null && this.gdvPreNoCompeleteMonthPlan.DataKeys[i]["MonthPlanId"].ToString().Length != 0)
                {
                    _monthId = Convert.ToInt32(this.gdvPreNoCompeleteMonthPlan.DataKeys[i]["MonthPlanId"].ToString());
                    _count++;
                    type = 3;
                }
            }
        }
        //持续进行工作
        for (int i = 0; i < this.gdvContinueMonthList.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvContinueMonthList.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvContinueMonthList.DataKeys[i]["MonthPlanId"] != null && this.gdvContinueMonthList.DataKeys[i]["MonthPlanId"].ToString().Length != 0)
                {
                    _monthId = Convert.ToInt32(this.gdvContinueMonthList.DataKeys[i]["MonthPlanId"].ToString());
                    _count++;
                    type = 4;
                }
            }
        }
        if (_count == 1)
        {
            //判断是否为评估人，如果该条计划的评估人是当前用户则不能修改该条计划

            string _url = "../WebCommon/VerifyCircruitDisplay.aspx?PlanId=" + _monthId + "&PlanType=2";
            Page.RegisterStartupScript("windowOpen",
               "<script language=javascript>window.open('" + _url + "','quarterplandetailmodify','height=150,width=550,top=250,left=300,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");

        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能查看一个月计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个月计划", Page);
            return;
        }
    }

    /// <summary>
    /// 分解到周计划中
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnResolve_Click(object sender, EventArgs e)
    {
        object[] _value = new object[1];
        int _monthId = 0;
        int _count = 0;
        BLL.MonthPlanManager dllMonthPlanManager = new MonthPlanManager();
        BLL.MonthPlanDetailManager dllMonthPlanDetailManager = new MonthPlanDetailManager();
        for (int i = 0; i < this.gdvMonthList.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvMonthList.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvMonthList.DataKeys[i]["MonthPlanId"] != null && this.gdvMonthList.DataKeys[i]["MonthPlanId"].ToString().Length != 0)
                {

                    _monthId = Convert.ToInt32(this.gdvMonthList.DataKeys[i]["MonthPlanId"].ToString());
                    _value[0] = _monthId;
                    //if (objUserInfo.UserName != "admin")
                    //{
                    _count++;
                    int val = dllMonthPlanManager.IsMonthPlanResolve(_value);
                    if (val == 0)
                    {
                        if (dllMonthPlanManager.MonthPlanToWeekPlan(_value) > 0)
                        {
                            Utility.HttpHelp.alert("分解成功！", this.Page);
                        }
                    }
                    //else
                    //{
                    //    Utility.HttpHelp.alert("该月计划已分解到周中！", this.Page);
                    //}
                    //}
                    else
                    {
                        //_count++;
                        if (dllMonthPlanManager.MonthPlanToWeekPlan(_value) > 0)
                        {
                            Utility.HttpHelp.alert("分解成功！", this.Page);
                        }
                    }
                }

            }
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择要分解的本月计划Id", this.Page);
        }
    }

    /// <summary>
    /// 本月修改
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModifyMonth_Click(object sender, EventArgs e)
    {
        string department = drpDepartment.SelectedItem.Value;
        object[] _valueMonth = new object[1];
        int _count = 0;
        int _monthId = 0;
        for (int i = 0; i < this.gdvMonthList.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvMonthList.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvMonthList.DataKeys[i]["MonthPlanId"] != null && this.gdvMonthList.DataKeys[i]["MonthPlanId"].ToString().Length != 0)
                {
                    _monthId = Convert.ToInt32(this.gdvMonthList.DataKeys[i]["MonthPlanId"].ToString());

                    _count++;

                }
            }
        }
        if (_count == 1)
        {

            //判断是否计划二次评估完成， 评估完成不允许修改。
            object[] _value = new object[1];
            _value[0] = _monthId;
            DataTable monthplan = dllMonthPlanManager.get(MonthPlanManager.field.MonthPlanId.ToString(), _value);
            if (monthplan.Rows.Count > 0)
            {
                if (Convert.ToInt32(monthplan.Rows[0]["PlanSendState"]) >= 4 && Convert.ToInt32(monthplan.Rows[0]["PlanSendState"]) != 9)
                {
                    Utility.HttpHelp.alert("计划已二次评估完成，不允许修改！", Page);
                    return;
                }
            }

            //判断是否已被分解
            //if (objUserInfo.UserName != "admin")
            //{
            //    _valueMonth[0] = _monthId;
            //    int val = dllMonthPlanManager.IsMonthPlanResolve(_valueMonth);
            //    if (val == 0)
            //    {
            //        _count++;
            //    }
            //    else
            //    {
            //        Utility.HttpHelp.alert("该月计划已经分解到周中", this.Page);
            //        return;
            //    }
            //}

            //判断是否为评估人，如果该条计划的评估人是当前用户则不能修改该条计划

            //Model.UserInfo objUser = new Model.UserInfo();
            //object[] _user = new object[1];
            //_user[0] = objUser.UserName;
            //DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
            //if (_userTable.Rows.Count > 0)
            //{
            //    object[] _username = new object[3];
            //    _username[0] = objUserInfo.UserName;
            //    _username[1] = _userTable.Rows[0]["RealName"].ToString();
            //    _username[2] = _monthId;
            //    DataTable _iSEvaluatePeople = dllMonthPlan.get(MonthPlanManager.field.EvaluatePeople.ToString(), MonthPlanManager.field.MonthPlanId.ToString(), _username);
            //    if (_iSEvaluatePeople.Rows.Count == 0 && objUserInfo.UserName != "admin" && plansendstate != 9)
            //    {
            //        Utility.HttpHelp.alert("非评估人不能修改计划", Page);
            //    }
            //    else
            //    {
            string _url = "MonthPlanModify.aspx?Id=" + _monthId + "&url=MonthPlanList&MonthDate=" + this.drpMonthDate.SelectedValue + "&depart=" + department + "&Year=" + this.drpYear.SelectedValue + "&Quarter=" + this.drpQuarterDate.SelectedValue + "&Month=" + this.drpMonthDate.SelectedValue;
            Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
            return;
            //    }
            //}

        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能修改一个月计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个月计划", Page);
            return;
        }
    }

    /// <summary>
    /// 上月修改
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModifyPrevMonth_Click(object sender, EventArgs e)
    {
        string department = drpDepartment.SelectedItem.Value;

        int _count = 0;
        int _monthId = 0;
        for (int i = 0; i < this.gdvPreNoCompeleteMonthPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvPreNoCompeleteMonthPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvPreNoCompeleteMonthPlan.DataKeys[i]["MonthPlanId"] != null && this.gdvPreNoCompeleteMonthPlan.DataKeys[i]["MonthPlanId"].ToString().Length != 0)
                {
                    _monthId = Convert.ToInt32(this.gdvPreNoCompeleteMonthPlan.DataKeys[i]["MonthPlanId"].ToString());
                    _count++;
                }
            }
        }
        if (_count == 1)
        {

            //判断是否计划二次评估完成， 评估完成不允许修改。
            object[] _value = new object[1];
            _value[0] = _monthId;
            DataTable monthplan = dllMonthPlanManager.get(MonthPlanManager.field.MonthPlanId.ToString(), _value);
            if (monthplan.Rows.Count == 0)
            {
                if (Convert.ToInt32(monthplan.Rows[0]["PlanSendState"]) >= 4 && Convert.ToInt32(monthplan.Rows[0]["PlanSendState"]) != 9)
                {
                    Utility.HttpHelp.alert("计划已二次评估完成，不允许修改！", Page);
                    return;
                }
            }

            //判断是否为评估人，如果该条计划的评估人是当前用户则不能修改该条计划

            //Model.UserInfo objUser = new Model.UserInfo();
            //object[] _user = new object[1];
            //_user[0] = objUser.UserName;
            //DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
            //if (_userTable.Rows.Count > 0)
            //{
            //object[] _username = new object[3];
            //_username[0] = objUserInfo.UserName;
            //_username[1] = _userTable.Rows[0]["RealName"].ToString();
            //_username[2] = _monthId;
            //DataTable _iSEvaluatePeople = dllMonthPlan.get(MonthPlanManager.field.EvaluatePeople.ToString(), MonthPlanManager.field.MonthPlanId.ToString(), _username);
            //if (_iSEvaluatePeople.Rows.Count == 0 && objUserInfo.UserName != "admin")
            //{
            //    Utility.HttpHelp.alert("非评估人不能修改计划", Page);
            //}
            //else
            //{
            string _url = "MonthPlanModify.aspx?Id=" + _monthId + "&url=MonthPlanList&MonthDate=" + Utility.HttpHelp.getParamsInt("Id") + "&depart=" + department + "&Year=" + this.drpYear.SelectedValue + "&Quarter=" + this.drpQuarterDate.SelectedValue + "&Month=" + this.drpMonthDate.SelectedValue;
            Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
            return;
            //}
            //}

        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能修改一个月计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个月计划", Page);
            return;
        }
    }

    /// <summary>
    /// 持续修改
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModifyContinue_Click(object sender, EventArgs e)
    {
        string department = drpDepartment.SelectedItem.Value;

        int _count = 0;
        int _monthId = 0;
        for (int i = 0; i < this.gdvContinueMonthList.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvContinueMonthList.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvContinueMonthList.DataKeys[i]["MonthPlanId"] != null && this.gdvContinueMonthList.DataKeys[i]["MonthPlanId"].ToString().Length != 0)
                {
                    _monthId = Convert.ToInt32(this.gdvContinueMonthList.DataKeys[i]["MonthPlanId"].ToString());
                    _count++;
                }
            }
        }
        if (_count == 1)
        {

            //判断是否计划二次评估完成， 评估完成不允许修改。
            object[] _value = new object[1];
            _value[0] = _monthId;
            DataTable monthplan = dllMonthPlanManager.get(MonthPlanManager.field.MonthPlanId.ToString(), _value);
            if (monthplan.Rows.Count == 0)
            {
                if (Convert.ToInt32(monthplan.Rows[0]["PlanSendState"]) >= 4 && Convert.ToInt32(monthplan.Rows[0]["PlanSendState"]) != 9)
                {
                    Utility.HttpHelp.alert("计划已二次评估完成，不允许修改！", Page);
                    return;
                }
            }

            //判断是否为评估人，如果该条计划的评估人是当前用户则不能修改该条计划

            //Model.UserInfo objUser = new Model.UserInfo();
            //object[] _user = new object[1];
            //_user[0] = objUser.UserName;
            //DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
            //if (_userTable.Rows.Count > 0)
            //{
            //    object[] _username = new object[2];
            //    _username[0] = _userTable.Rows[0]["RealName"].ToString();
            //    _username[1] = _monthId;
            //    DataTable _iSEvaluatePeople = dllMonthPlan.get(MonthPlanManager.field.EvaluatePeople.ToString(), MonthPlanManager.field.MonthPlanId.ToString(), _username);
            //    if (_iSEvaluatePeople.Rows.Count == 0 && objUserInfo.UserName != "admin")
            //    {
            //        Utility.HttpHelp.alert("非评估人不能修改计划", Page);
            //    }
            //    else
            //    {
            string _url = "MonthPlanModify.aspx?Id=" + _monthId + "&url=MonthPlanList&MonthDate=" + Utility.HttpHelp.getParamsInt("Id") + "&depart=" + department + "&Year=" + this.drpYear.SelectedValue + "&Quarter=" + this.drpQuarterDate.SelectedValue + "&Month=" + this.drpMonthDate.SelectedValue;
            Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
            return;
            //    }
            //}

        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能修改一个月计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个月计划", Page);
            return;
        }
    }


    /// <summary>
    /// 查看分解
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnMonthResolve_Click(object sender, EventArgs e)
    {
        int _count = 0;
        int _monthId = 0;
        string _monthPlanSortId = string.Empty;
        for (int i = 0; i < this.gdvMonthList.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvMonthList.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked)
            {
                if (ckb.Checked == true)
                {
                    if (this.gdvMonthList.DataKeys[i]["MonthPlanId"] != null && this.gdvMonthList.DataKeys[i]["MonthPlanId"].ToString().Length != 0)
                    {
                        _monthId = Convert.ToInt32(this.gdvMonthList.DataKeys[i]["MonthPlanId"].ToString());
                        _monthPlanSortId = this.gdvMonthList.DataKeys[i]["MonthPlanSortId"].ToString();
                        _count++;
                    }
                }
            }
        }
        if (_count == 1)
        {
            string _url = "MonthPlanResolveAddForTip.aspx?_MonthPlanId=" + _monthId + "&_MonthPlanSortId=" + _monthPlanSortId + "&Url=MonthPlanList.aspx";
            Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
            return;
        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能修改一个月计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个月计划", Page);
            return;
        }
    }


    /// <summary>
    /// 分解到员工月计划
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnResolveToUserMonthPlan_Click(object sender, EventArgs e)
    {
        int _count = 0;
        string _url = string.Empty;
        int _monthId = 0;
        for (int i = 0; i < this.gdvMonthList.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvMonthList.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                _count++;
                //弹出新页面
                _monthId = Convert.ToInt32(this.gdvMonthList.DataKeys[i]["MonthPlanId"].ToString());
                _url = "../UserPlanMonth/ResolveMonthPlanToUserMonthPlan.aspx?_MonthPlanId=" + _monthId + "&_DepartmentName=" + HttpUtility.UrlEncode(this.drpDepartment.SelectedItem.Text) + "&_Source=" + HttpUtility.UrlEncode(this.drpMonthDate.SelectedItem.Text);


            }
        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("请选择一条月计划！", this.Page);
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择要分解的本月计划Id", this.Page);
        }
        BLL.UserPlanMonth bllUserPlanMonth = new UserPlanMonth();
        DataTable dt = bllUserPlanMonth.getUserPlanMonthByQuarterPlanId(new object[] { _monthId });
        if (dt.Rows.Count > 0)
        {
            Page.RegisterClientScriptBlock("confirm", "<script>confirm('此计划已分解到" + dt.Rows[0]["MasterPeople"] + "');</script>");
            //Utility.HttpHelp.alert("此计划已分解到！", this.Page);
            Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }
        else
        {
            Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }
    }






    /// <summary>
    /// 添加月总结
    /// </summary>
    /// <param name="sender"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Utility.HttpHelp.windowOpen("AddMonthSummary.aspx?Url=MonthPlanList.aspx&QuarterDate=" + this.drpQuarterDate.SelectedValue + "MonthDate=" + this.drpMonthDate.SelectedValue + "&Year=" + this.drpYear.SelectedValue + "&Department=" + this.drpDepartment.SelectedItem.Text, this.Page);
    }


    /// <summary>
    /// <param name="e"></param>
    /// 添加附件（已过期）
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        //if (this.HMonthSummaryId.Value.Length > 0)
        //{
        //    if (sender.Equals(this.btnUploadMonthSummary))
        //    {
        //        //定向到添加本月附件路径页面
        //        string _url = "../WebCommon/AttachmentPath.aspx?PlanId=" + this.HMonthSummaryId.Value + "&PlanType=16&Url=MonthPlanList.aspx";
        //        Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','quarterplandetailmodify','height=40,width=400,top=300,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
        //    }
        //    else
        //    {
        //        //定向到添加上月附件路径页面
        //        string _url = "../WebCommon/AttachmentPath.aspx?PlanId=" + this.HMonthSummaryId.Value + "&PlanType=13&Url=MonthPlanList.aspx";
        //        Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','quarterplandetailmodify','height=40,width=400,top=300,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
        //    }
        //}
        //else
        //{
        //    if (sender.Equals(this.btnUploadMonthSummary))
        //    {
        //        Utility.HttpHelp.alert("请先添加本月总结", this.Page);
        //    }
        //    else
        //    {
        //        Utility.HttpHelp.alert("请先添加上月总结", this.Page);
        //    }

        //}

    }


    /// <summary>
    /// 添加修改月总结事件。
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAddMonthSummary_Click(object sender, EventArgs e)
    {
        this.btnSaveMonthSummary.Visible = true;
        this.btnAddMonthSummary.Visible = false;
        this.txtMonthSummary.ReadOnly = false;
        if (this.txtMonthSummary.Text == "注：工作部署不少于3条，总字数不少于60个字。")
        {
            this.txtMonthSummary.Text = "";
        }
        //this.lblMonthSummary.Visible = false;
    }

    /// <summary>
    /// 添加上周总结
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAddPreMonthSummary_Click(object sender, EventArgs e)
    {
        this.btnSavePreMonthSummary.Visible = true;
        this.btnAddPreMonthSummary.Visible = false;
        //this.txtPreMonthSummary.ReadOnly = false;
        //if (this.txtPreMonthSummary.Text == "注：工作总结不少于3条，总字数不少于60个字。")
        //{
        //    this.txtPreMonthSummary.Text = "";
        //}
        //this.lblPreMonthSummary.Visible = false;
    }

    /// <summary>
    /// 下载事件(已过期）
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDownMonthSummary_Click(object sender, EventArgs e)
    {
        if (sender.Equals(this.btnDownMonthSummary))
        {
            string path = this.HAttachmentPath.Value;
            FileDownload(path);
        }
        else
        {
            //string path = this.HPreAttachmentPath.Value;
            //FileDownload(path);
        }
    }


    /// <summary>
    /// 保存上月总结
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSavePreMonthSummary_Click(object sender, EventArgs e)
    {
        if (this.drpDepartment.SelectedItem.Text != "请选择部门")
        {

            if (this.HMonthSummaryId.Value.Length > 0)
            {


                //修改
                object[] _value = new object[11];
                _value[0] = Convert.ToInt32(this.drpMonthDate.SelectedValue);

                _value[1] = objUserInfo.UserName;
                BLL.UserInfoManager dllUserInfo = new BLL.UserInfoManager();
                DataTable dt = dllUserInfo.get(BLL.UserInfoManager.field.UserName.ToString(), new object[] { objUserInfo.UserName });
                _value[2] = Convert.ToInt32(dt.Rows[0]["UserId"]);
                _value[3] = this.drpDepartment.SelectedItem.Text;
                _value[4] = Convert.ToInt32(this.HMonthSummaryId.Value);
                _value[5] = this.txtWorkItemfinish.Text;
                _value[6] = this.txtWorkItemunfinish.Text;
                _value[7] = this.txtfinishdetail.Text;
                _value[8] = this.txtreason.Text;
                _value[9] = this.txtimprovement.Text;
                _value[10] = this.txtCreatecontent.Text;
                int val = new BLL.MonthSummary().editMonthSummary(_value);
                if (val > 0)
                {
                    bindGridView(this.gdvPreMonthList);
                }
                else
                {
                    Utility.HttpHelp.alert("修改失败", this.Page);
                }
            }
            else
            {
                //添加
                object[] _value = new object[9];
                _value[0] = Convert.ToInt32(this.drpMonthDate.SelectedValue);
                _value[1] = objUserInfo.UserName;
                _value[2] = this.drpDepartment.SelectedItem.Text;
                _value[3] = this.txtWorkItemfinish.Text;
                _value[4] = this.txtWorkItemunfinish.Text;
                _value[5] = this.txtfinishdetail.Text;
                _value[6] = this.txtreason.Text;
                _value[7] = this.txtimprovement.Text;
                _value[8] = this.txtCreatecontent.Text;
                int val = new BLL.MonthSummary().add(_value);
                if (val > 0)
                {
                    bindGridView(this.gdvPreMonthList);
                }
                else
                {
                    Utility.HttpHelp.alert("添加失败", this.Page);
                }
            }
            if (sender.Equals(this.btnSaveMonthSummary))
            {
                this.btnAddMonthSummary.Visible = true;
                this.btnSaveMonthSummary.Visible = false;
                this.txtMonthSummary.ReadOnly = true;
                //this.lblMonthSummary.Visible = true;
            }
            if (sender.Equals(this.btnSavePreMonthSummary))
            {
                this.btnAddPreMonthSummary.Visible = true;
                this.btnSavePreMonthSummary.Visible = false;
                //this.txtPreMonthSummary.ReadOnly = true;
                //this.lblPreMonthSummary.Visible = true;
            }
        }
        else
        {
            Utility.HttpHelp.alert("请选择部门", this.Page);
        }
    }


}
